<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
			function showTime(){
				/*获取时间的年月日时分秒*/
				var date=new Date();
				var y=date.getFullYear();
				var mon=date.getMonth();
				var d=date.getDate();
				var h=date.getHours();
				var m=date.getMinutes();
				var s=date.getSeconds();
			    /*向html文档中写入时间*/
			   document.getElementById("today").innerHTML=y+"年"+mon+"月"+d+"日  "+h+"时"+m+"分"+s+"秒";
			}
			/*设置定时器,每秒调用一次函数*/
			var flag1=window.setInterval("showTime()",1000);
		</script>
	</head>
	<body>
		<div id="today"></div>
		<a href="javascript:window.clearInterval(flag1)">停止定时器clearInterval</a>
	</body>
</html>
